<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/7/6 0006
 * Time: 上午 9:41
 */
namespace app\home\controller;
use think\Amapserver;
use think\Controller;
use think\Weixin;

class  Login extends Controller{
    public function login(){
        $WeixinController=new  Weixin();
        $userinfo=$WeixinController->getweixinuserinfo();
        $getSignPackage=$WeixinController->getSignPackage();
//       dump($getSignPackage);
        $this->assign('getSignPackage', $getSignPackage);
        $this->assign('userinfo', $userinfo);
        session('userinfo',$userinfo);
//    dump($userinfo);
         return $this->fetch();
    }
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($echoStr){
            echo $echoStr;
            exit;
        }
    }
    //转换坐标
    public function getlocations(){
        $data=$this->request->param();
        $lat=$data['lat'];
        $lng=$data['lng'];
//      $location=('108.9499,34.19921');
        $location=$lng.",".$lat;
        $Amapserver=new Amapserver();
//        $areainfo =$Amapserver->inputtips($location);
        $areainfo=$Amapserver->convert($location);
        $areainfos=$areainfo['locations'];
        $areainfo=$Amapserver->regeo($areainfos);
        //获取当前定位时的坐标
//        if($lat && $lng){
//            $location=$lng.",".$lat;
//            session("location_agent", $location);
//        }
//        session("agent_loction_time", time());
//        $gpschange = new \Org\Util\Gps();
//        $gpschange->gcj_encrypt($lat,$lat);
//        //获取最近距离最近的区域
//        $areainfo=M('area')->order(" ROUND(6378.138*2*ASIN(SQRT(POW(SIN((".$lat."*PI()/180-substring_index(location, ',', -1)*PI()/180)/2),2)+COS(".$lat."*PI()/180)*COS(substring_index(location, ',', -1)*PI()/180)*POW(SIN((".$lng."*PI()/180-substring_index(location, ',', 1) *PI()/180)/2),2)))*1000) asc ")->find();
//        if($areainfo){
//            $this->ajaxReturn(array('status'=>sizeof($areainfo),'data'=>$areainfo));
//        }else{
//            $this->ajaxReturn(array('status'=>sizeof($areainfo),'data'=>$areainfo));
//        }
//        dump($areainfo);
        return json(['data'=>$areainfo]);
    }
}